﻿@using ZhouYu.NewWorld.Model
@{
    Layout = null;
    var cashnumber = ViewBag.userInfos as List<UserInfo>;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style>
        .right {
            display: none
        }
    </style>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/style.css" />
    <link href="~/assets/css/codemirror.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/font/css/font-awesome.min.css" />
    <link href="~/static/common/layui/css/layui.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/static/admin/css/style.css" />

    <!--[if lte IE 8]>
      <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/static/common/jquery-3.3.1.min.js"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <script src="~/assets/js/typeahead-bs2.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/static/common/layui/layui.js"></script>
    <script src="~/assets/layer/layer.js" type="text/javascript"></script>
    <script src="~/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="~/Scripts/Format.js"></script>
    <script src="~/static/common/layui/lay/modules/laytpl.js"></script>
    <title>现金账户管理</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="" id="Other_Management">
            <div class="border clearfix">
                <span class="l_f">
                    <a href="#" class="btn btn-danger" id="add">&nbsp;添加</a>
                </span>
            </div>
            <div class="list_style">
                <table class="layui-hide" id="test" lay-filter="demo"></table>
                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除账号</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="dels">删除记录</a>
                </script>
                <script type="text/html" id="switchTpl">
                    <input type="checkbox" id="{{d.CashRecord_Id}}" name="IsEnable" value="{{d.CashRecord_State}}" lay-skin="switch" lay-text="审核|未审核" lay-filter="sexDemo" {{ d.CashRecord_State == '1' ? 'checked' : ' ' }}/>
                </script>
            </div>
        </div>
    </div>
    <div class="right" id="app">
        <fieldset class="layui-elem-field layui-field-title">
            <legend></legend>
        </fieldset>
        <div>
            <div class="layui-form-item">
                <input type="hidden" name="Cash_Id" id="Cash_Id" class="layui-input" />
                <label class="layui-form-label">账户余额</label>
                <div class="layui-input-block">
                    <input type="text" name="Cash_balance" id="Cash_balance" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">账户名</label>
                <div class="layui-input-block">
                    <input type="text" name="Cash_LoginName" id="Cash_LoginName" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">账户密码</label>
                <div class="layui-input-block">
                    <input type="password" name="Cash_LoginPwd" id="Cash_LoginPwd" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户编号</label>
            <div class="layui-input-block">
                <select name="User_Id" id="User_Id" style="margin-left:10px">
                    @foreach (var user in cashnumber)
                    {
                        <option value="@user.User_Id">@user.User_RealName</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form" id="isvip">
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" value="1" id="Cash_State" name="Cash_State" lay-text="开启|关闭" checked="" lay-skin="switch" lay-filter="switchEnable" />
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="button" id="commit" value="立即提交" class="layui-btn" />
            </div>
        </div>
    </div>
</body>
</html>
<script>
    //显示
    $(function () {
        layui.use('table', function () {
            var table = layui.table;
             var form = layui.form;
            table.render({
                elem: '#test'
                , url: '/Cashnumber/CashnuumberInfo'
                , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                , cols: [[
                    { type: 'checkbox' } //开启复选框
                    , { field: 'CashRecord_Id', title: '操作记录编号', sort: true }
                    , { field: 'Cash_Id', title: '账户ID', sort: true }
                    , { field: 'User_Id', title: '用户ID', sort: true }
                    , { field: 'CashRecord_Money', title: '操作金额', sort: true }
                    , { field: 'CashRecord_State',templet: '#switchTpl',title: '审核状态', unresize: true }
                    , { field: 'CashRecord_OperationMethod', title: '操作方式 返现/提现', sort: true }
                    , { field: 'CashRecord_Channel', title: '渠道 某某银行或旅游卷', sort: true }
                    , { field: 'CashRecord_Effective', title: '有效时间', sort: true, templet: "<div>{{Format(d.CashRecord_Effective ,'yyyy-MM-dd hh:mm:ss')}}</div>" }
                    , { field: 'CashRecord_CreateTime', title: '操作时间', sort: true, templet: "<div>{{Format(d.CashRecord_CreateTime ,'yyyy-MM-dd hh:mm:ss')}}</div>" }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width:250 }
                ]]
                , page: true
                , id: 'testReload'
            });

            //状态
            form.on('switch(sexDemo)', function (obj) {
                var tip = "启用";
                var CashNnmber = {}

                CashNnmber.CashRecord_Id = this.id;

                if (this.value === "1") {
                    tip = "停用";
                    CashNnmber.Cash_State = 0;
                } else {
                    CashNnmber.Cash_State = 1;
                }

                layer.confirm('真的要' + tip + '吗', function (index) {

                    $.ajax({
                        url: "/Cashnumber/UpdateState",
                        type: "post",
                        data:CashNnmber,
                        success: function (result) {
                            if (result.Success) {
                                layer.msg(tip + '成功！', { title: '提示框', icon: 1, time: 2000 }, function () { window.location.reload() });
                            } else {
                                layer.msg(tip + '失败！');
                            }
                        }
                    })
                })
            });

            //监听行工具事件
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                if (obj.event == 'edit') {
                    layer.open({
                        type: 1,
                        title: '修改信息',
                        area: ['800px', '500'],
                        shadeClose: false,
                        content: $("#app"),
                    });
                    $.ajax({
                        type: "post",
                        url: "/Cashnumber/GetCashuNumber?id=" + data.Cash_Id,
                        success: function (result) {
                            if (result.Success) {
                                $("#Cash_Id").val(result.data.Cash_Id);
                                $("#Cash_balance").val(result.data.Cash_balance);
                                $("#Cash_LoginName").val(result.data.Cash_LoginName);

                                $("#Cash_LoginPwd").attr('type', 'text');
                                $("#Cash_LoginPwd").val(result.data.Cash_LoginPwd);
                                $("#User_Id").val(result.data.User_Id);

                                if (result.data.Cash_State === 1) {
                                    $("#isvip em").text("开启");
                                    //$("#isvip .layui-form-switch").addClass("layui-form-onswitch");
                                } else {
                                    $("#isvip em").text("关闭");
                                    $("#isvip .layui-form-switch").removeClass("layui-unselect layui-form-onswitch");
                                }
                            }
                        }
                    });

                    $("#commit").click(function () {
                        var cashnumber = {};
                        cashnumber.Cash_Id = $("#Cash_Id").val();
                        cashnumber.Cash_balance = $("#Cash_balance").val();
                        cashnumber.Cash_LoginName = $("#Cash_LoginName").val();
                        cashnumber.Cash_LoginPwd = $("#Cash_LoginPwd").val();
                        cashnumber.User_Id = $("#User_Id").val();
                        if ($("#Cash_State").prop("checked")) {
                            cashnumber.Cash_State = 1;
                        }
                        else {
                            cashnumber.Cash_State = 0;
                        }

                        $.ajax({
                            type: "post",
                            data: cashnumber,
                            url: "/Cashnumber/UpdateCashnumber",
                            success: function (result) {
                                if (result.Success) {
                                    layer.msg('修改成功！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    }
                                        , function () { window.location.reload() });
                                } else {
                                    layer.msg('修改失败！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    });
                                }
                            }
                        });
                    });
                } else if (obj.event == 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url: "/Cashnumber/DeleteCash?id=" + data.Cash_Id,
                            type: "post",
                            success: function (data) {
                                if (data.Success) {
                                    layer.msg('删除成功！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    }, function () {
                                        TableReload();
                                        layer.close(index);
                                    });
                                    window.location.reload();
                                }
                                else {
                                    layer.msg('删除失败！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    });
                                }
                            }
                        });
                    });
                } else if (obj.event == 'dels') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url: "/Cashnumber/DeleteCashNumber?id=" +  data.CashRecord_Id,
                            type: "post",
                            success: function (data) {
                                if (data.Success) {
                                    layer.msg('删除成功！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    }, function () {
                                        TableReload();
                                        layer.close(index);
                                    });
                                    window.location.reload();
                                }
                                else {
                                    layer.msg('删除失败！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    });
                                }
                            }
                        });
                    });
                }
            });
        });
        //添加
        $("#add").click(function () {
            layer.open({
                type: 1,
                title: "添加",
                area: ['800px', '500'],
                shadeClose: false,
                content: $("#app"),
            });
            $("#Cash_balance").val(null);
            $("#Cash_LoginName").val(null);
            $("#Cash_LoginPwd").val(null);

            $("#commit").click(function () {
                if ($("#Cash_balance").val() != null && $("#Cash_balance").val() != "" && $("#Cash_LoginName").val() != null && $("#Cash_LoginName").val() != "" && $("#Cash_LoginPwd").val() != null && $("#Cash_LoginPwd").val() != "") {
                    var cashnumber = {};
                    cashnumber.Cash_balance = $("#Cash_balance").val();
                    cashnumber.Cash_LoginName = $("#Cash_LoginName").val();
                    $("#Cash_LoginPwd").attr('type','password');
                    cashnumber.Cash_LoginPwd = $("#Cash_LoginPwd").val();
                    if ($("#Cash_State").prop("checked")) {
                        cashnumber.Cash_State = 1;
                    }
                    else {
                        cashnumber.Cash_State = 0;
                    }
                    cashnumber.User_Id = $("#User_Id").val();


                    $.ajax({
                        type: "post",
                        data: cashnumber,
                        url: "/Cashnumber/AddCashnumber",
                        success: function (result) {
                            if (result.Success) {
                                layer.msg('添加成功！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                }
                                    , function () { window.location.reload() });
                            } else {
                                layer.msg('添加失败！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                });
                            }
                        },
                    });
                }
                else {
                    layer.msg('不能为空！', {
                        title: '提示框',
                        icon: 1,
                        time: 2000
                    });
                }
            });
        });
    });
</script>


<script>
    jQuery(function ($) {
        var oTable1 = $('#sample-table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                { "orderable": false, "aTargets": [0, 2, 3, 6] }// 制定列不参与排序
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
    });



    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', { icon: 1, time: 1000 });
        });
    }
    //积分浏览
    function integration_history(id) {
        layer.open({
            type: 1,
            title: '积分获取记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#integration_history'),
        })
        $('#integration_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });

    };
    //浏览记录

    function Browse_history(id) {
        layer.open({
            type: 1,
            title: '浏览记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#Browse_history'),
        })
        $('#Browse_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });
    }


    //购物记录
    function Order_history(id) {
        layer.open({
            type: 1,
            title: '购物记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#Order_history'),
        });
        $('#Order_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });
    }
</script>
